package com.ck.minio;

import io.minio.MinioClient;

public class FileUploader {

    public static void main(String[] args){
        try {
            // 使用MinIO服务的URL，端口，Access key和Secret key创建一个MinioClient对象
            MinioClient minioClient = new MinioClient("http://127.0.0.1:9000", "minioadmin", "minioadmin");

            // 检查存储桶是否已经存在
            String bucketName = "miniotest";
            boolean isExist = minioClient.bucketExists(bucketName);
            if (isExist) {
                System.out.println("Bucket already exists.");
            } else {
                // 创建一个名为asiatrip的存储桶，用于存储照片的zip文件。
                minioClient.makeBucket(bucketName);
            }

            // 使用putObject上传一个文件到存储桶中。
            minioClient.putObject(bucketName, "MyQRCode.png", "d:/MyQRCode.png");
            System.out.println("d:/MyQRCode.png is successfully uploaded as asiaphotos.zip to `miniotest` bucket.");
        } catch (Exception e) {
            System.out.println("Error occurred: " + e);
        }
    }
}
